<html>
<head><meta charset="utf-8"><title>Inconsistency in usage parser · wg-cli · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/220302-wg-cli/index.html">wg-cli</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/220302-wg-cli/topic/Inconsistency.20in.20usage.20parser.html">Inconsistency in usage parser</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203400779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/220302-wg-cli/topic/Inconsistency%20in%20usage%20parser/near/203400779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CreepySkeleton <a href="https://rust-lang.github.io/zulip_archive/stream/220302-wg-cli/topic/Inconsistency.20in.20usage.20parser.html#203400779">(Jul 09 2020 at 15:30)</a>:</h4>
<p>While working on empty values, I have found pretty weird behavior of usage parser.</p>
<p>This is how I perceive usage strings:</p>
<div class="codehilite"><pre><span></span><code><span class="c1">// This clearly reads to me as &quot;optional option that optionally takes value&quot;</span>
<span class="n">Arg</span>::<span class="n">from</span><span class="p">(</span><span class="s">&quot;-o, --option [opt]&quot;</span><span class="p">)</span><span class="w"></span>
<span class="c1">// This reads to me as &quot;optional option with a required value&quot;</span>
<span class="n">Arg</span>::<span class="n">from</span><span class="p">(</span><span class="s">&quot;-o, --option &lt;opt&gt;&quot;</span><span class="p">)</span><span class="w"></span>
</code></pre></div>


<p>But here's how clap understands it:</p>
<div class="codehilite"><pre><span></span><code><span class="c1">// &quot;optional option with a required value&quot;</span>
<span class="n">Arg</span>::<span class="n">from</span><span class="p">(</span><span class="s">&quot;-o, --option [opt]&quot;</span><span class="p">)</span><span class="w"></span>
<span class="c1">// &quot;required option with a required value&quot;</span>
<span class="n">Arg</span>::<span class="n">from</span><span class="p">(</span><span class="s">&quot;-o, --option &lt;opt&gt;&quot;</span><span class="p">)</span><span class="w"></span>
</code></pre></div>


<p>Is it just me or which do you think should be correct?</p>



<a name="203635712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/220302-wg-cli/topic/Inconsistency%20in%20usage%20parser/near/203635712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/220302-wg-cli/topic/Inconsistency.20in.20usage.20parser.html#203635712">(Jul 12 2020 at 09:27)</a>:</h4>
<p>Huh, this seems very subjective</p>



<a name="203635764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/220302-wg-cli/topic/Inconsistency%20in%20usage%20parser/near/203635764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/220302-wg-cli/topic/Inconsistency.20in.20usage.20parser.html#203635764">(Jul 12 2020 at 09:28)</a>:</h4>
<p>I want to tend towards the first snippet according to my understanding of usage string conventions</p>



<a name="203635774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/220302-wg-cli/topic/Inconsistency%20in%20usage%20parser/near/203635774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pksunkara <a href="https://rust-lang.github.io/zulip_archive/stream/220302-wg-cli/topic/Inconsistency.20in.20usage.20parser.html#203635774">(Jul 12 2020 at 09:28)</a>:</h4>
<p>But I don't know how the user would specify the <code>required</code> option case</p>



<a name="203757061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/220302-wg-cli/topic/Inconsistency%20in%20usage%20parser/near/203757061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> CreepySkeleton <a href="https://rust-lang.github.io/zulip_archive/stream/220302-wg-cli/topic/Inconsistency.20in.20usage.20parser.html#203757061">(Jul 13 2020 at 19:07)</a>:</h4>
<p>I presume required options are much less common than optional ones. I think it makes sense to require more verbose syntax for this case:</p>
<div class="codehilite"><pre><span></span><code>// &quot;required option with an optional value&quot;
Arg::from(&quot;-o, --option [opt]&quot;).required(true)
// &quot;required option with a required value&quot;
Arg::from(&quot;-o, --option &lt;opt&gt;&quot;).required(true)
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>